package com.itheima.app.controller.pmsController;


import com.itheima.app.manager.pmsManager.ProductCategoryManager;
import com.itheima.autoconfig.oss.OssTemplate;
import com.itheima.commons.R;
import com.itheima.domain.db.pms.PmsProductCategory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
public class ProductCategoryController {

    @Autowired
    ProductCategoryManager productCategoryManager;

    @Autowired
    OssTemplate ossTemplate;
    /*//添加商品分类
    @PostMapping("/productCategory/create")
    public R addProductCategory(@RequestBody PmsProductCategory pmsProductCategory){

        return productCategoryManager.addProductCategory(pmsProductCategory);
    }*/

    //删除商品分类
    @PostMapping("/productCategory/delete/{id}")
    public R deleteProductCategory(@PathVariable Integer id){

        return productCategoryManager.deleteProductCategory(id);
    }

    //查询所有一级分类及子分类
    @GetMapping("/productCategory/list/withChildren")
    public R withChildren(){
        return productCategoryManager.withChildren();
    }

    //分页查询商品分类
    @GetMapping("/productCategory/list/{parentId}")
    public R findPageProductCategory(@PathVariable Integer parentId,@RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize){

        return productCategoryManager.findPageProductCategory(parentId,pageNum,pageSize);
    }

    //修改导航栏显示状态
    @PostMapping("/productCategory/update/navStatus")
    public R updateNavStatus(Integer navStatus, Integer [] ids){
        return productCategoryManager.updateNavStatus(navStatus,ids);
    }

    //修改显示状态
    @PostMapping("/productCategory/update/showStatus")
    public R updateShowStatus(Integer [] ids,Integer showStatus){
        return productCategoryManager.updateShowStatus(ids,showStatus);
    }

    //修改商品分类
    @PostMapping("/productCategory/update/{id}")
    public R updateProductCategory(@PathVariable Integer id,@RequestBody PmsProductCategory pmsProductCategory){
        return productCategoryManager.updateProductCategory(id,pmsProductCategory);
    }

    @GetMapping("/productCategory/{id}")
    public R selectById(@PathVariable Integer id){
        return productCategoryManager.selectById(id);
    }

    //修改导航栏显示状态
    @PostMapping("/aliyun/oss/upload")
    public R uploadFile(MultipartFile photoFile) throws IOException {
        return productCategoryManager.uploadFile(photoFile);
    }
}
